#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
# Run a simple backup of the Bacula build directory
#   then verify the Volume to the catalog.           
#
TestName="verify-voltocat-test"
JobName=VerifyVol
. scripts/functions

cwd=`pwd`
scripts/cleanup
scripts/copy-test-confs
touch ${cwd}/build/src/dird/verify-dummy # create dummy file
echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >tmp/bconcmds
@output /dev/null
messages
@$out tmp/log0.out
setdebug level=1 storage=File sd
label storage=File volume=TestVolume001
run level=full job=$JobName yes
wait
messages
@$out tmp/log1.out
run level=full job=$JobName yes
wait
messages
@# 
@# now do a verify to catalog
@#
@$out ${cwd}/tmp/log2.out
setdebug level=12 dir
run job=VerifyVolume level=VolumeToCatalog
yes
wait
messages
@$out ${cwd}/tmp/log4.out
setdebug level=12 dir
run job=VerifyVolume jobid=1 level=VolumeToCatalog
yes
wait
messages
@$out ${cwd}/tmp/log3.out
@#
@# Delete file and make some changes to be backed up
@exec "rm $cwd/build/src/dird/verify-dummy"
@exec "sh -c 'touch ${cwd}/build/src/dird/*.o'"
@# now run and Incremental job
@#setdebug level=50 dir
run job=$JobName Accurate=yes level=Incremental yes
wait
messages
run job=VerifyVolume Accurate=yes level=VolumeToCatalog
yes
wait
messages
quit
END_OF_DATA

run_bacula

sleep 2
check_for_zombie_jobs storage=File 
stop_bacula

grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
bstat=$?
grep "^  Termination: *Verify OK" tmp/log2.out 2>&1 >/dev/null
rstat=$?
grep "^  Termination: *Verify OK" tmp/log3.out 2>&1 >/dev/null
dstat=$?
grep "Verify JobId: *2" tmp/log2.out 2>&1 >/dev/null
dstat=$(($dstat + $?))
grep "Verify JobId: *1" tmp/log4.out 2>&1 >/dev/null
dstat=$(($dstat + $?))
grep "Verify Job: *VerifyVol" tmp/log4.out 2>&1 >/dev/null
dstat=$(($dstat + $?))

end_test
